package test.org.nanotek.jpa.persistence.dao;

import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Metamodel;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class DaoMetaModelPrint {

	EntityManagerFactory emf;
	EntityManager em;
	
	private Logger log = Logger.getLogger(DaoMetaModelPrint.class);
	
	@Before
	public void start()
	{ 
		emf = Persistence.createEntityManagerFactory("musicbrainz");
		em = emf.createEntityManager();
	}
	
	@Test
	public void verifyModel()
	{ 
		Metamodel metaModel = em.getMetamodel();
		Set <EntityType<?>> entities = metaModel.getEntities();
		for(EntityType<?> et : entities)
		{ 
//			Set<Attribute<? super X, ?>>  attributes = et.getAttributes(); 
//			System.out.println("METAMODEL CLASSNAME :" + et.getName());
			log.debug("METAMODEL ENTITY TYPE NAME " + et.getName());
		}
	
	}
	
	@After
	public void shutDown()
	{ 
		if (em !=null && em.isOpen()) 
			em.close();
		if (emf !=null && emf.isOpen()) 
			emf.close();
	}
}
